<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="__STATIC__/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/frame/static/css/style.css">
    <link rel="icon" href="__STATIC__/frame/static/image/code.png">
</head>
<body class="body">
<form method="post" action="" id="form">
    <div class="layui-form-item">
        <label class="layui-form-label">第一级分类</label>
        <div class="layui-input-block">
           <select name="classes_id" class="layui-select" style="width: 100%">
               {foreach $class as $value}
               <option value="{$value['id']}">{$value['class_name']}</option>
               {/foreach}
           </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">第二级分类</label>
        <div class="layui-input-block">
            <select name="branchid"  class="layui-select" style="width: 100%">
                {foreach $branch as $value}
                <option value="{$value['id']}">{$value['branch_name']}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">第三级分类名称</label>
        <div class="layui-input-block">
            <input type="text" name="three_level_name" class="layui-input">
        </div>
    </div>
<div class="layui-form-item">
    <label class="layui-form-label">第三级分类名称</label>
    <div class="layui-input-block">
        <select name="recommend" class="layui-select">
            <option value="0">否</option>
            <option value="1">是</option>
        </select>
    </div>
</div>
</form>
<div style="text-align: center">
    <button class="layui-btn" id="tijiao">提交</button>
</div>
<script src="__STATIC__/frame/layui/layui.all.js" charset="utf-8"></script>
<script src="__STATIC__/js/jquery.3.3.1.min.js" charset="utf-8"></script>
<script src="__STATIC__/js/maowenke.js" charset="utf-8"></script>
<script>
    $("[name=classes_id]").change(function () {
        var $classeid = $(this).val();
        $.post("{:url('api/get_Branch')}",{id:$classeid},function (data) {
            if(data.code==200){
                $("[name=branchid]").empty();
                $str = '';
                $.each(data.data,function (i,v) {
                    $str += ' <option value="'+v.id+'">'+v.branch_name+'</option>';
                });
                $("[name=branchid]").append($str);
            }
        });
    });
$("#tijiao").click(function () {
    ajaxs($("#form"),"{:url('add/three_level')}",function (data) {
        if(data.code==200){
            layer.msg(data.msg);
            setTimeout(function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            },1500);
        }else{
            layer.msg(data.msg);
        }
    });
//    var $branchid = $("[name=branchid]").val();
//    var $str      = $("[name=three_level_name]").val();
//    $.post("{:url('add/three_level')}",{branchid:$branchid,str:$str},function (data) {
//        if(data.code==200){
//           layer.msg(data.msg);
//           setTimeout(function () {
//               var index = parent.layer.getFrameIndex(window.name);
//               parent.layer.close(index);
//           },1500);
//        }else{
//            layer.msg(data.msg);
//        }
//    })
})
</script>
</body>
</html>